package com.atguigu.atcrowdfunding.util;

import java.util.List;

/**
 * @author xzt
 * @create 2021-02-14 15:23
 */
public class Page {

    private Integer pageNo;
    private Integer pageSize;
    private List datas;
    private Integer totalSize;
    private Integer totalNo;

    public Page() {
    }

    public Page(Integer pageNo, Integer pageSize){
        if(pageNo <= 0){
            this.pageNo = 1;
        }else{
            this.pageNo = pageNo;
        }

        if(pageSize <= 0){
            this.pageSize = 10;
        }else{
            this.pageSize = pageSize;
        }

    }

    public Page(Integer pageNo, Integer pageSize, List datas, Integer totalSize, Integer totalNo) {
        this.pageNo = pageNo;
        this.pageSize = pageSize;
        this.datas = datas;
        this.totalSize = totalSize;
        this.totalNo = totalNo;
    }

    public Integer getPageNo() {
        return pageNo;
    }

    public void setPageNo(Integer pageNo) {
        this.pageNo = pageNo;
    }

    public Integer getPageSize() {
        return pageSize;
    }

    public void setPageSize(Integer pageSize) {
        this.pageSize = pageSize;
    }

    public List getDatas() {
        return datas;
    }

    public void setDatas(List datas) {
        this.datas = datas;
    }

    public Integer getTotalSize() {
        return totalSize;
    }

    public void setTotalSize(Integer totalSize) {
        this.totalSize = totalSize;
        this.totalNo = totalSize % this.pageSize == 0 ? totalSize / this.pageSize : (totalSize / this.pageSize) + 1;
    }

    public Integer getTotalNo() {
        return totalNo;
    }

    private void setTotalNo(Integer totalNo) {
        this.totalNo = totalNo;
    }

    public Integer startIndex(){
        return (this.pageNo - 1) * pageSize;
    }

    @Override
    public String toString() {
        return "Page{" +
                "pageNo=" + pageNo +
                ", pageSize=" + pageSize +
                ", datas=" + datas +
                ", totalSize=" + totalSize +
                ", totalNo=" + totalNo +
                '}';
    }
}
